package com.zbkj.front.service.impl;

import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zbkj.common.constants.Constants;
import com.zbkj.common.constants.RedisKeyConstants;
import com.zbkj.common.enums.CommonStatusEnum;
import com.zbkj.common.enums.InformationTypEnum;
import com.zbkj.common.enums.ProjectStatusEnum;
import com.zbkj.common.enums.ReportApplyStatusEnum;
import com.zbkj.common.exception.CommonException;
import com.zbkj.common.exception.ExceptionCodeEnum;
import com.zbkj.common.exception.ResultException;
import com.zbkj.common.model.project.*;
import com.zbkj.common.model.user.User;
import com.zbkj.common.oss.OssClientUtil;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.project.*;
import com.zbkj.common.response.UploadResponse;
import com.zbkj.common.response.project.ClientProjectInfoResponse;
import com.zbkj.common.response.project.InformationResponse;
import com.zbkj.common.response.project.ProjectStatusCountResponse;
import com.zbkj.common.response.project.ReportInfoResponse;
import com.zbkj.common.token.FrontTokenComponent;
import com.zbkj.common.utils.CommonUtil;
import com.zbkj.common.utils.LocalDateUtil;
import com.zbkj.common.utils.RedisUtil;
import com.zbkj.common.vo.project.ProjectModifyConditionVo;
import com.zbkj.common.vo.project.ProjectQueryVo;
import com.zbkj.front.service.ProjectHandleService;
import com.zbkj.service.service.SystemConfigService;
import com.zbkj.service.service.UploadService;
import com.zbkj.service.service.project.*;
import com.zbkj.service.service.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Auther:
 * @Date: 2024/7/6 14:41
 * @Description:
 */
@Slf4j
//@Service
public class ProjectHandleServiceImpl implements ProjectHandleService {
    /*
    @Autowired
    private FrontTokenComponent frontTokenComponent;
    @Autowired
    private UserService userService;
    @Autowired
    private SystemConfigService systemConfigService;
    @Autowired
    private ProjectInfoService projectInfoService;
    @Autowired
    private ProjectInformationService projectInformationService;
    @Autowired
    private OssClientUtil ossClientUtil;
    @Autowired
    private UploadService uploadService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private EstimateInformationService estimateInformationService;
    @Autowired
    private ProjectReportService projectReportService;
    @Autowired
    private ProjectReportItemService  projectReportItemService;

    @Override
    public ProjectStatusCountResponse getProjectStatusCount() {
        Long userId = frontTokenComponent.getLoginUserId();
        ProjectStatusCountResponse response = new ProjectStatusCountResponse();
        response.setToEstimateCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus(),ProjectStatusEnum.WITHDRAWN.getStatus()),null,userId));
        response.setInEstimateCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.IN_ESTIMATE.getStatus()),null,userId));
        response.setCompletEstimateCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.COMPLET_ESTIMATE.getStatus()),null,userId));
        response.setInReportCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.IN_REPORT.getStatus()),null,userId));
        response.setFinishCount(projectInfoService.getProjectStatusCount(Lists.newArrayList(ProjectStatusEnum.FINISH.getStatus()),null,userId));
        return response;
    }

    @Override
    public UploadResponse informationUpload(Integer type, MultipartFile multipartFile) {
        if(!InformationTypEnum.clientTypeCheck(type)) {
            throw new CommonException("文件类型参数错误");
        }
        if(multipartFile == null || multipartFile.isEmpty()) {
            throw new CommonException("上传文件不能为空");
        }
        UploadResponse uploadResponse = new UploadResponse();
        uploadResponse.setFileName(multipartFile.getOriginalFilename());
        String fileType = FilenameUtils.getExtension(uploadResponse.getFileName());
        if(!CommonUtil.fileTypeCheck(Constants.CLIENT_FILE_TYPES,fileType)) {
            throw new CommonException("上传文件类型错误");
        }
        uploadResponse.setExtName(fileType);
        uploadResponse.setFileSize(multipartFile.getSize());
        String fileUrl =  uploadService.informationUpload(fileType, multipartFile);
        uploadResponse.setUrl(fileUrl);
        return uploadResponse;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createProject(ClientProjectRequest projectRequest) {
        //资料文件检查
        this.informationRequestCheck(projectRequest.getInformationRequestList());
        User user = userService.getLoginUserInfo();

        String currentDay = LocalDateUtil.localDateToStr(LocalDate.now(),LocalDateUtil.YYYYMMDD);
        //每日新建项目数量
        String dayLimitStr = systemConfigService.getValueByKey(Constants.PROJECT_DAY_LIMIT_CFG);
        //最大新建项目数量
        String totalimitStr = systemConfigService.getValueByKey(Constants.PROJECT_TOTAL_LIMIT_CFG);
        //新建项目保存前 数量限制检查
        this.newProjectLimitBeforSaveCheck(user.getId(),currentDay,dayLimitStr,totalimitStr);
        projectRequest.setId(null);
        //检查项目名称是否存在
        Integer nameRepeatNum = projectInfoService.projectNameRepeatCheck(user.getId(),projectRequest.getProjectName(),projectRequest.getId());
        if(nameRepeatNum > 0) {
            throw new CommonException("项目名称已存在");
        }
        ProjectInfo projectInfo = this.projectReqToPojo(projectRequest,user);
        projectInfoService.save(projectInfo);
        List<ProjectInformation> pinfList = this.informationReqToPojo(projectInfo, user, projectRequest.getInformationRequestList());
        projectInformationService.saveBatch(pinfList,pinfList.size());

        //用户新建项目每日incr缓存处理
        String dayIncrKey = String.format(Constants.PROJECT_NEWNUM_DAY_KEY,currentDay,user.getId());
        long dayIncrNum = redisUtil.incr(dayIncrKey, 1);
        redisUtil.expire(dayIncrKey,Constants.PROJECT_NEWNUM_DAY_EXPIRE);
        if(StringUtils.isNotBlank(dayLimitStr)) {
            long dayLimit = Long.valueOf(dayLimitStr);
            if(dayLimit < dayIncrNum) {
                throw new CommonException("新建项目已超出今日最大限制数");
            }
        }
    }

    @Override
    public PageInfo<ClientProjectInfoResponse> projectList(ClientProjectQueryRequest queryRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        if(Objects.isNull(queryRequest.getQueryStatus())) {
            throw new CommonException("缺少项目状态查询参数");
        }
        ProjectQueryVo queryVo = new ProjectQueryVo();
        if(ProjectStatusEnum.isToEstimate(queryRequest.getQueryStatus())) {
            queryVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus(),ProjectStatusEnum.WITHDRAWN.getStatus()));
        } else {
            queryVo.setStatusList(Lists.newArrayList(queryRequest.getQueryStatus()));
        }
        queryVo.setProjectName(queryRequest.getProjectName());
        queryVo.setUserId(userId);
        queryVo.setStatusSort(queryRequest.getQueryStatus());
        queryVo.setSource(1);
        //分页查询项目列表
        PageInfo<ProjectInfo> projectPage = projectInfoService.projectList(queryVo,queryRequest.getPage(),queryRequest.getLimit());
        List<ClientProjectInfoResponse> responseList = Lists.newArrayList();
        for(ProjectInfo projectInfo : projectPage.getList()) {
            ClientProjectInfoResponse response = new ClientProjectInfoResponse();
            BeanUtils.copyProperties(projectInfo, response);
            responseList.add(response);
        }
        return CommonPage.copyPageInfo(projectPage, responseList);
    }

    @Override
    public void remindProject(Long projectId) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId,userId);
        if(!ProjectStatusEnum.isToEstimate(projectDb.getStatus())) {
            throw new CommonException("项目正在加紧处理中，请耐心等待");
        }
        *//*if(projectDb.getRemindFlag() != 0) {
            throw new CommonException("项目正在加紧处理中，请耐心等待");
        }*//*
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectDb.getId());
        //updateProject.setRemindFlag(1);
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus()));
        boolean updateFlag = projectInfoService.updateProject(updateProject, conditionVo);
        if(!updateFlag) {
            throw new CommonException("项目正在加紧处理中，请耐心等待");
        }
    }

    @Override
    public void withdrawProject(Long projectId) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId,userId);
        if(!(ProjectStatusEnum.isToEstimate(projectDb.getStatus())
                || ProjectStatusEnum.isInEstimate(projectDb.getStatus()))) {
            throw new CommonException("项目状态已变更，撤回操作失败");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectDb.getId());
        //撤回操作-项目属性设置为初始化状态
        projectInfoService.withdrawnAttrInit(updateProject);
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.TO_ESTIMATE.getStatus(),ProjectStatusEnum.IN_ESTIMATE.getStatus()));
        boolean updateFlag = projectInfoService.updateProject(updateProject, conditionVo);
        if(!updateFlag) {
            throw new CommonException("项目信息已变更，撤回操作失败");
        }
    }

    @Override
    public void delProject(Long projectId) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId,userId);
        if(!ProjectStatusEnum.isWithdrawn(projectDb.getStatus())) {
            throw new CommonException("项目状态不为撤回状态，不能删除");
        }
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectDb.getId());
        updateProject.setDeleteFlag(1);
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.WITHDRAWN.getStatus()));
        boolean updateFlag = projectInfoService.updateProject(updateProject, conditionVo);
        if(!updateFlag) {
            throw new CommonException("项目信息已变更，删除操作失败");
        }
    }

    @Override
    public ClientProjectInfoResponse getProjectInfo(Long projectId) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId,userId);
        ClientProjectInfoResponse  response = new ClientProjectInfoResponse();
        BeanUtils.copyProperties(projectDb,response);
        //获取当前有效的项目资料文件列表
        List<ProjectInformation> dbList = projectInformationService.getValidProjectInformationList(projectId);
        List<InformationResponse> fileResponseList = Lists.newArrayList();
        for(ProjectInformation pojo : dbList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(ossClientUtil.addDomain(vo.getFilePath()));
            //vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            fileResponseList.add(vo);
        }
        response.setInformationResponseList(fileResponseList);
        return response;
    }

    @Override
    public List<InformationResponse> getValidProjectFileList(Long projectId) {
        //获取当前有效的项目资料文件列表
        List<ProjectInformation> dbList = projectInformationService.getValidProjectInformationList(projectId);
        List<InformationResponse> fileResponseList = Lists.newArrayList();
        for(ProjectInformation pojo : dbList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(ossClientUtil.addDomain(vo.getFilePath()));
            //vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            fileResponseList.add(vo);
        }
        return fileResponseList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void resubmitProject(ClientProjectRequest projectRequest) {
        //资料文件检查
        this.informationRequestCheck(projectRequest.getInformationRequestList());
        User user = userService.getLoginUserInfo();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectRequest.getId(),user.getId());
        if(!ProjectStatusEnum.isWithdrawn(projectDb.getStatus())) {
            throw new CommonException("项目状态不为撤回状态，不能重新提交");
        }
        if(!StringUtils.equals(projectDb.getProjectName(),projectRequest.getProjectName())) {
            //检查项目名称是否存在
            Integer nameRepeatNum = projectInfoService.projectNameRepeatCheck(user.getId(),projectRequest.getProjectName(),projectRequest.getId());
            if(nameRepeatNum > 0) {
                throw new CommonException("项目名称已存在");
            }
        }
        ProjectInfo updateProject = this.projectReqToPojo(projectRequest,user);
        updateProject.setId(projectDb.getId());
        updateProject.setStatus(ProjectStatusEnum.TO_ESTIMATE.getStatus());
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.WITHDRAWN.getStatus()));
        boolean updateFlag = projectInfoService.updateProject(updateProject, conditionVo);
        if(!updateFlag) {
            throw new CommonException("项目信息已变更，请稍后重试");
        }
        //将当前有效资料更新为历史状态
        projectInformationService.updateStatusToHis(updateProject.getId());
        List<ProjectInformation> pinfList = this.informationReqToPojo(updateProject, user, projectRequest.getInformationRequestList());
        projectInformationService.saveBatch(pinfList,pinfList.size());
    }

    @Override
    public void projectConfirm(Long projectId, Integer status) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId, userId);
        //项目更新对象
        ProjectInfo updateProject = new ProjectInfo();
        updateProject.setId(projectDb.getId());
        //更新条件对象
        ProjectModifyConditionVo conditionVo = new ProjectModifyConditionVo();
        if(ProjectStatusEnum.isCompletEstimate(status)) { //估算结束确认
            //估算中项目才可进行估算结束确认
            if(!ProjectStatusEnum.isInEstimate(projectDb.getStatus())) {
                throw new CommonException("项目未估算完成,请耐心等待");
            }
            //检查是否上传手工结算文件
            if(projectDb.getEstimateFlag().intValue() != 1) {
                throw new CommonException("项目未估算完成,请耐心等待");
            }
            updateProject.setStatus(status);
            updateProject.setEstimateConfirmTime(new Date());
            //设置更新检查条件
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.IN_ESTIMATE.getStatus()));
        } else if(ProjectStatusEnum.isInReport(status)) { //申请报告
            if(!ProjectStatusEnum.isCompletEstimate(projectDb.getStatus())) {
                throw new CommonException("项目信息已变更，请稍后再试");
            }
            if(!ReportApplyStatusEnum.applyStatusCheck(projectDb.getReportApplyStatus())) {
                throw new CommonException("项目报告正在处理中,请耐心等待");
            }
            //updateProject.setStatus(status);
            updateProject.setReportApplyStatus(ReportApplyStatusEnum.IN_APPLY.getStatus());
            //设置更新检查条件
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.COMPLET_ESTIMATE.getStatus()));
            //报告申请状态检查条件
            conditionVo.setReportApplyStatusList(ReportApplyStatusEnum.applyCheckStatusList());
        } else if(ProjectStatusEnum.isFinish(status)) { //项目完成确认
            if(!ProjectStatusEnum.isInReport(projectDb.getStatus())) {
                throw new CommonException("项目报告未完成,请耐心等待");
            }
            //检查是否完成上传报告
            if(projectDb.getReportFlag().intValue() != 1) {
                throw new CommonException("项目报告未完成,请耐心等待");
            }
            updateProject.setStatus(status);
            updateProject.setCompleteTime(new Date());
            //设置更新检查条件
            conditionVo.setStatusList(Lists.newArrayList(ProjectStatusEnum.IN_REPORT.getStatus()));
        } else {
            throw new CommonException("操作状态参数错误");
        }
        boolean updateFlag = projectInfoService.updateProject(updateProject, conditionVo);
        if(!updateFlag) {
            throw new CommonException("项目信息已变更，请稍后再试");
        }
    }

    @Override
    public void informationDownload(ClientProjectDownloadRequest downloadRequest, HttpServletResponse response) {
        Long projectId = downloadRequest.getProjectId();
        if(!InformationTypEnum.clientDownloadTypeCheck(downloadRequest.getFileType())) {
            throw new CommonException("下载文件类型错误");
        }
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(projectId, userId);
        *//*if(projectDb.getLockState().intValue() != 0) {
            throw new CommonException("密码错误已到达上限，请联系管理员解锁后再进行导出操作");
        }*//*
        Integer status = Objects.isNull(downloadRequest.getFileId()) ? null : CommonStatusEnum.VALID_STATUS.getStatus();
        EstimateInformation information = estimateInformationService.getOneRecord(downloadRequest.getFileId(),projectId, downloadRequest.getFileType(),status);
        if(Objects.isNull(information) || StringUtils.isBlank(information.getFilePath())) {
            throw new CommonException("文件还未生成，请稍后再试");
        }
        //检查项目密码
        *//*if(!projectDb.getProjectPwd().equals(CommonUtil.encryptPassword(downloadRequest.getProjectPwd(), CommonUtil.SERCRET_KEY))) {
            String pwdErrorkey = String.format(RedisKeyConstants.PROJECT_PWDERROR_KEY,projectId);
            long errorNum = redisUtil.incr(pwdErrorkey,1);
            if(Constants.PROJECT_PWD_ERROR_LIMIT > errorNum) {
                throw new ResultException(ExceptionCodeEnum.PROJECT_PWD_ERROR.getCode(),String.format(ExceptionCodeEnum.PROJECT_PWD_ERROR.getMessage(),(Constants.PROJECT_PWD_ERROR_LIMIT-errorNum)));
            } else {
                //输入密码次数超过限制--更新项目锁状态
                projectInfoService.projectLockUpdate(projectId, 1);
                throw new CommonException("密码错误已到达上限，请联系管理员解锁后再进行导出操作");
            }
        }*//*
        //文件路径增加oss内网访问域名
        String netPath = ossClientUtil.addInnerDomain(information.getFilePath());
        String originalFileName = information.getFileName();
        InputStream redIn = null;
        ServletOutputStream outputStream = null;
        try{
            URL netUrl = new URL(netPath);
            redIn = netUrl.openConnection().getInputStream();
            response.setContentType("application/octet-stream");
            response.addHeader("Access-Control-Expose-Headers","Content-Disposition,File-Type");
            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(originalFileName, "UTF-8"));
            String fileType = FilenameUtils.getExtension(originalFileName);
            response.addHeader("File-Type",fileType);
            outputStream = response.getOutputStream(); //字节流
            byte[] bytes = new byte[1024*10];
            int read;
            do {
                read = redIn.read(bytes);
                outputStream.write(bytes,0,read);
            }while (-1 != read);
            outputStream.flush();
        } catch (Exception e) {
            log.error("项目资料下载异常-projectId:{}-fileId{}-error:",projectId,information.getId(),e);
            throw new CommonException("读取文件失败，请稍后再试");
        } finally {
            IOUtils.closeQuietly(redIn);
            IOUtils.closeQuietly(outputStream);
        }
    }

    @Override
    public ReportInfoResponse getReportInfo(ClientResportInfoRequest queryRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(queryRequest.getProjectId(), userId);
        *//*if(StringUtils.isNotBlank(queryRequest.getProjectPwd())
                && !projectDb.getProjectPwd().equals(CommonUtil.encryptPassword(queryRequest.getProjectPwd(), CommonUtil.SERCRET_KEY))) {
            throw new CommonException("项目密码错误");
        }*//*
        //项目基本信息赋值
        ReportInfoResponse response = new ReportInfoResponse();
        response.setProjectId(projectDb.getId());
        response.setProjectName(projectDb.getProjectName());
        response.setBudgetAmount(projectDb.getBudgetAmount());
        response.setCreateTime(projectDb.getCreateTime());
        response.setEstimateFlag(projectDb.getEstimateFlag());
        if(ProjectStatusEnum.isFinish(projectDb.getStatus())) {
            response.setEndTime(projectDb.getCompleteTime());
        } else {
            response.setEndTime(projectDb.getEstimateConfirmTime());
        }
        if(projectDb.getEstimateFlag().intValue() != 1) {
            //服务端未填写报告信息。
            return response;
        }
        ProjectReport reportDb = projectReportService.getByProjectId(queryRequest.getProjectId());
        if(Objects.nonNull(reportDb)) { //未赋值
            ReportInfoResponse.InfoResponse infoResponse = new ReportInfoResponse.InfoResponse();
            //List<ReportInfoResponse.ItemResponse> itemResponseList = Lists.newArrayList();
            if(StringUtils.isBlank(queryRequest.getProjectPwd())) {
                *//*for (ProjectReportItem itemDb : itemDbList) {
                    ReportInfoResponse.ItemResponse itemResponse = new ReportInfoResponse.ItemResponse();
                    itemResponseList.add(itemResponse);
                }*//*
            } else {
                BeanUtils.copyProperties(reportDb,infoResponse);
                List<ProjectReportItem> itemDbList = projectReportItemService.getItemsByProjectId(queryRequest.getProjectId());
                BigDecimal totalFactor = BigDecimal.ZERO;
                for (ProjectReportItem itemDb : itemDbList) {
                    totalFactor = totalFactor.add(itemDb.getAdjustFactor());
                    *//*ReportInfoResponse.ItemResponse itemResponse = new ReportInfoResponse.ItemResponse();
                    BeanUtils.copyProperties(itemDb,itemResponse);
                    itemResponseList.add(itemResponse);*//*
                }
                infoResponse.setTotalFactor(totalFactor);
            }
            response.setInfoResponse(infoResponse);
            //response.setItemList(itemResponseList);
        }
        return response;
    }

    @Override
    public PageInfo<InformationResponse> getInformationList(InformationQueryRequest queryRequest) {
        Long userId = frontTokenComponent.getLoginUserId();
        //获取项目信息-检查是否存在|是否登录用户创建
        ProjectInfo projectDb = this.getProjectAndCheck(queryRequest.getProjectId(), userId);
        if(!InformationTypEnum.clientDownloadTypeCheck(queryRequest.getQueryType())) {
            throw new CommonException("资料类型参数错误");
        }
        PageInfo<EstimateInformation> pageInfo = estimateInformationService.getInformationList(queryRequest);
        List<EstimateInformation> dbList = pageInfo.getList();
        List<InformationResponse> responseList = Lists.newArrayList();
        for (EstimateInformation pojo : dbList) {
            InformationResponse vo = new InformationResponse();
            BeanUtils.copyProperties(pojo, vo);
            vo.setFilePath(null); //不对客户端保留资料下载地址
            vo.setCreatePhone(CommonUtil.maskMobile(vo.getCreatePhone()));
            responseList.add(vo);
        }
        return CommonPage.copyPageInfo(pageInfo,responseList);
    }

    *//**
     * 项目资料信息检查
     * @param informationRequestList
     *//*
    private void informationRequestCheck(List<ClientInformationRequest> informationRequestList) {
        *//*ClientInformationRequest fileRequest = informationRequestList.stream().
                filter(v->v.getFileType() == InformationTypEnum.TYPE1.getType())
                .findFirst().orElse(null);
        if(Objects.isNull(fileRequest)) {
            throw new CommonException("请上传实施方案资料");
        }*//*
    }

    *//**
     * 创建项目-数量限制检查
     * @param userId
     *//*
    private void newProjectLimitBeforSaveCheck(Long userId,String currentDay,String dayLimitStr,String totalimitStr) {
        if(StringUtils.isNotBlank(dayLimitStr)) {
            String key = String.format(Constants.PROJECT_NEWNUM_DAY_KEY,currentDay,userId);
            long cachNum = redisUtil.incr(key, 0);
            long dayLimit = Long.valueOf(dayLimitStr);
            if(dayLimit < (cachNum+1)) {
                throw new CommonException("新建项目已超出今日最大限制数");
            }
        }
        if(StringUtils.isNotBlank(totalimitStr)) {
            int totalNum = projectInfoService.getProjectUserCount(userId);
            int totalLimit = Integer.valueOf(totalimitStr);
            if(totalLimit < (totalNum+1)) {
                throw new CommonException("新建项目已超出最大限制数");
            }
        }
    }

    *//**
     * 项目信息请求对象转换为pojo
     * @param projectRequest
     * @param user
     * @return
     *//*
    private ProjectInfo projectReqToPojo(ClientProjectRequest projectRequest, User user) {
        ProjectInfo projectInfo = new ProjectInfo();
        BeanUtils.copyProperties(projectRequest,projectInfo);
        projectInfo.setUserId(user.getId());
        projectInfo.setCompanyName(user.getCompanyName());
        *//*if(StringUtils.isNotBlank(projectRequest.getProjectPwd())) {
            projectInfo.setProjectPwd(CommonUtil.encryptPassword(projectRequest.getProjectPwd(), CommonUtil.SERCRET_KEY));
        }*//*
        projectInfo.setCreateTime(new Date());
        return projectInfo;
    }

    *//**
     * 资料请求对象转为pojo
     * @param projectInfo
     * @param user
     * @param informationRequestList
     * @return
     *//*
    private List<ProjectInformation> informationReqToPojo(ProjectInfo projectInfo, User user,List<ClientInformationRequest> informationRequestList) {
        List<ProjectInformation> pinfList = Lists.newArrayList();
        //获取当前文件批次号
        String  batchNo = CommonUtil.getRandomStr("");
        for (ClientInformationRequest infReq : informationRequestList) {
            ProjectInformation projectIfomation = new ProjectInformation();
            BeanUtils.copyProperties(infReq,projectIfomation);
            projectIfomation.setProjectId(projectInfo.getId());
            projectIfomation.setBatchNo(batchNo);
            projectIfomation.setCreateId(user.getId());
            projectIfomation.setCreateName(user.getRealName());
            projectIfomation.setFilePath(ossClientUtil.clearDomain(infReq.getFilePath()));
            pinfList.add(projectIfomation);
        }
        return pinfList;
    }

    *//**
     * 获取项目信息-检查是否存在|是否登录用户创建
     * @param projectId
     * @param userId
     * @return
     *//*
    private ProjectInfo getProjectAndCheck(Long projectId, Long userId) {
        ProjectInfo projectDb = projectInfoService.getById(projectId);
        if(Objects.isNull(projectDb) || projectDb.getDeleteFlag() != 0) {
            throw new CommonException("项目信息已不存在");
        }
        if(projectDb.getUserId().longValue() != userId.longValue()) {
            throw new CommonException("无权限操作该项目");
        }
        return projectDb;
    }*/
}
